#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    ll ans = 0;
    map<ll, ll> mp1, mp2, mpx, mpy;
    for(int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        ans += mp1[b - a] + mp2[a + b] + mpx[a] + mpy[b];
        mp1[b - a] ++;
        mp2[a + b] ++;
        mpx[a] ++;
        mpy[b] ++;
    }
    cout << ans * 2 << endl;
}

int main() {
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}